﻿$(document).ready(function() {
    $(".addData").click(function() {
        addFrame = dhtmlwindow.open('iframebox_add', 'iframe', '/Forms/SingleTable/SingleTableEdit.aspx?type=add', '增加记录', 'width=680px,height=500px,center=1,top=100px,resize=1,scrolling=1');
    });
    $(".editData").click(function() {
        var currentRecid = $(this).attr("recid");
        if (currentRecid != "") {
            editFrame = dhtmlwindow.open('iframebox_edit', 'iframe', '/Forms/SingleTable/SingleTableEdit.aspx?type=edit&recid=' + currentRecid, '编辑记录', 'width=680px,height=500px,center=1,top=100px,resize=1,scrolling=1');
        }
    });
    $(".deleteData").click(function() {
        var currentRecid = $(this).attr("recid");
        if (currentRecid != "") {
            $.alerts.confirm("您确定要删除当前数据吗？", "确定删除", function(result) {
                if (result) {
                    $.get("/Tools/DeleteRecord.aspx?table=" + tableName + "&filter=" + encodeURI("recid=" + currentRecid), function(data) {
                        if (data.toString().toLowerCase() == "true") {
                            $.alerts.alert("删除成功！", "成功", function() {
                                jQuery.refresh();
                            });
                        }
                        else {
                            $.alerts.alert("删除失败", "失败");
                        }
                    })
                }
            })
        }
    });
    $("#searchFilterAnchor").click(function() {
        if ($(".collapsed").length != 0) { //处于折叠状态
            $(this).removeClass("collapsed");
            $(".TableFilterDiv").show();
        }
        else {                            //处于打开状态
            $(this).addClass("collapsed");
            $(".TableFilterDiv").hide();
        }
    });

    $(".MainGrid tr").attr("title", "双击编辑").css("cursor", "pointer").hover(function() {
        if (!$(this).hasClass("ShowMenu"))
            $(this).css("backgroundColor", "#E7F2FF");
    },
            function() {
                if (!$(this).hasClass("ShowMenu"))
                    $(this).css("backgroundColor", "#FFF");
            }).dblclick(function() {
                $(this).find(".editData").click();
            });
    $(".MainGrid tr > td").addClass("UserMenuTarget")


    $.ContextMenuManager.CreateContextMenu({ menuID: "UserMenu", targetClass: "UserMenuTarget"},
                       { bindings: {
                                'GotoMainTable': function(target) {
                                                    alert("GotoMainTable");
                                                },
                                'EditRecord': function(target) {
                                                    $(target).parent().find(".editData:[recid]").click();
                                                    //$(target).parent("tr").addClass("ShowMenu").css("backgroundColor", "blue");
                                                },
                                'DeleteRecord': function(target) {
                                                    $(target).parent().find(".deleteData:[recid]").click();
                                                    //$(target).parent("tr").addClass("ShowMenu").css("backgroundColor", "blue");
                                                }
                            }
                        },
                        function(target) {
                            $(target).parent("tr").addClass("ShowMenu").css("backgroundColor", "blue");
                        },
                        function(target) {
                            $(target).parent("tr").removeClass("ShowMenu").css("backgroundColor", "");
                        }
                    );


});